
import React, { Component } from 'react'
import { Button } from 'antd'

// 1. 创建上下文
const Context = React.createContext()

const store = {
    'name': '开课吧',
    sayHi() {
        console.log(this.name)
    }
}

const withProvider = Comp => props => {
    return (
        <Context.Provider value={store}>
            <Comp {...props}></Comp>
        </Context.Provider>
    )
}

const withConsumer = Comp => props => {
    return (
        <Context.Consumer>
            {/* 必须内嵌一个函数 */}
            {value => <Comp {...props} value={value}></Comp>}
        </Context.Consumer>
    )
}


@withConsumer
class Inner extends Component {
    render() {
        return (
            <div>{this.props.value.name}</div>
        )
    }
}

@withProvider
class ContextCont extends Component {
    render() {
        return (
            <div>
                <Inner>asdsad</Inner>
            </div>
        )
    }
}

export default ContextCont